<!-- 表单 》 单选框 -->

<template>
  <el-form-item v-bind="formItem">
    <!-- 隐藏输入框，触发校验 -->
    <el-input v-show="false" :value="model" />

    <!-- 标签 -->
    <template v-if="hasLabelSlot" #label>
      <slot name="label" :label="formItem.label">{{ formItem.label }}</slot>
    </template>

    <el-button v-if="hasClear" :size="commonProps.size" class="CoreWeb-RadioClear" type="text" @click.stop="toClear">
      {{ clearText }}
    </el-button>

    <el-radio-group
      v-if="isBtn"
      v-model="model"
      v-bind="commonProps"
      :class="`${className} CoreWeb-RadioGroup`"
      @change="emitChange"
    >
      <el-radio-button
        v-for="(item, i) in selectData"
        :key="`${item[0]}-${i}`"
        :class="getHideClass(item)"
        :label="item[0]"
        :disabled="getDisabled(item)"
      >
        <span class="CoreWeb-radio-btn">
          <slot name="item" :item="item">
            <span>{{ item[1] }}</span>
            <span v-if="showRight" class="CoreWeb-radio-btn-right">{{ item[rightIndex] }}</span>
          </slot>
        </span>
      </el-radio-button>
    </el-radio-group>

    <el-radio-group
      v-else
      v-model="model"
      v-bind="commonProps"
      :class="`${className} CoreWeb-RadioGroup`"
      @change="emitChange"
    >
      <el-radio
        v-for="(item, i) in selectData"
        :key="`${item[0]}-${i}`"
        :class="getHideClass(item)"
        :label="item[0]"
        :disabled="getDisabled(item)"
      >
        <span class="CoreWeb-radio">
          <slot name="item" :item="item">
            <span>{{ item[1] }}</span>
            <span v-if="showRight" class="CoreWeb-radio-right">{{ item[rightIndex] }}</span>
          </slot>
        </span>
      </el-radio>
    </el-radio-group>
  </el-form-item>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import mixForm from '../mixForm'
import FormSelect from '../FormSelect'

const name = 'FormRadio'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name,

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [mixForm],

  /**
   * 属性注册 (抽取以便查阅)
   */
  props: CORE.WEB[name],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: FormSelect.computed,

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: FormSelect.methods,
}
</script>
